package com.clg.common.interceptor;

import com.clg.common.beans.SessionUser;
import com.clg.common.constants.Constants;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

/**
 * Created by usercai on 2016/9/26.
 */
public class LoginInterceptor implements Interceptor{

    @Override
    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
        SessionUser sessionUser = controller.getSessionAttr(Constants.USER_SESSION_KEY);
        if(sessionUser==null){
            controller.redirect("/login");
        }else{
            inv.invoke();
        }
    }
}
